#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    int w = this->width();
    int h = this->height();
    QRect rect(w/4, h/4, w/2, h/2);
    //设置画笔
    QPen pen;
    pen.setWidth(3);
    pen.setStyle(Qt::PenStyle::SolidLine);
    pen.setColor(Qt::GlobalColor::red);
    painter.setPen(pen);
    //设置材质
    QPixmap texturePixmap(":images/images/texture.jpg");
    //设置笔刷
    QBrush brush;
    brush.setStyle(Qt::TexturePattern);
    brush.setTexture(texturePixmap);
    painter.setBrush(brush);
    //图片
    QImage image(":images/images/qt.jpg");
    //绘图
//    painter.drawRect(rect);
    painter.drawImage(rect, image);
}

